using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace SyncUdp
{
    using DG.Tweening;
    using SyncUdp.Model;
    using SyncUdp.Network;
    using SyncUdp.UI;
    using SyncUdp.Utility;

    public class ArchitectureController : MonoBehaviour
    {
        private void Awake()
        {
            AddAllSingletons();
            IOCContainer.InitSingletons();
        }

        /// <summary>
        /// 添加所有单例
        /// </summary>
        void AddAllSingletons()
        {
            #region 特殊单例
            IOCContainer.AddInstance<IEventCenter>(new EventCenter());
            IOCContainer.AddInstance<IResourceManager>(new ResourceManager());
            IOCContainer.AddInstance<IGameManager>(new GameManager(this));
            IOCContainer.AddInstance<IUIManager>(new UIManager());
            #endregion

            #region 工具
            IOCContainer.AddInstance<IJsonUtility>(new JsonUtility());
            //IOCContainer.AddInstance<INetworkLogUtility>(new NetworkLogUtility());
            #endregion

            #region 数据
            IOCContainer.AddInstance<IPlayerModel>(new PlayerModel());
            #endregion

            #region 交互
            IOCContainer.AddInstance<INetworkSystem>(new NetworkSystem());
            IOCContainer.AddInstance<IPlayerSystem>(new PlayerSystem());
            #endregion
        }

        private void Start()
        {
            IOCContainer.GetInstance<IUIManager>().ShowUI(Enum.UIType.MainMenu);
        }

        private void Update()
        {
            IOCContainer.GetInstance<IEventCenter>().Update();
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                Cursor.visible = true;
                Cursor.lockState = CursorLockMode.None;
            }
        }
    }
}